
// QuadIntrinsicView.cpp : implementation of the CQuadIntrinsicView class
//

#include "stdafx.h"
#include "QuadIntrinsic.h"

#include "QuadIntrinsicDoc.h"
#include "QuadIntrinsicView.h"
#include "cvxImage.h"
#include "QuadPaint.h"
#include <conio.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CQuadIntrinsicView

IMPLEMENT_DYNCREATE(CQuadIntrinsicView, CView)

BEGIN_MESSAGE_MAP(CQuadIntrinsicView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND(ID_INTRINSIC_QUADPAINT, &CQuadIntrinsicView::OnIntrinsicQuadpaint)
	ON_COMMAND(ID_INTRINSIC_U, &CQuadIntrinsicView::OnIntrinsicU)
END_MESSAGE_MAP()

// CQuadIntrinsicView construction/destruction

CQuadIntrinsicView::CQuadIntrinsicView()
{
	// TODO: add construction code here

}

CQuadIntrinsicView::~CQuadIntrinsicView()
{
}

BOOL CQuadIntrinsicView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CQuadIntrinsicView drawing

void CQuadIntrinsicView::OnDraw(CDC* /*pDC*/)
{
	CQuadIntrinsicDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
}


// CQuadIntrinsicView printing

BOOL CQuadIntrinsicView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CQuadIntrinsicView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CQuadIntrinsicView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}


// CQuadIntrinsicView diagnostics

#ifdef _DEBUG
void CQuadIntrinsicView::AssertValid() const
{
	CView::AssertValid();
}

void CQuadIntrinsicView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CQuadIntrinsicDoc* CQuadIntrinsicView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQuadIntrinsicDoc)));
	return (CQuadIntrinsicDoc*)m_pDocument;
}
#endif //_DEBUG


// CQuadIntrinsicView message handlers

void CQuadIntrinsicView::OnIntrinsicQuadpaint()
{
	// TODO: Add your command handler code here

	//read in an image
	int leftOk = AfxMessageBox(_T("read an image "), MB_OK);
	string imageFile;
	//@todo

	//table_512_512.png  doll_512.png
	//table_left0.png  synthetic.tif
//	string imageFile = string("E:\\code\\QuadIntrinsic\\QuadIntrinsic\\QuadIntrinsic\\image\\doll_512.png");
	if (leftOk == IDOK)
	{
		CFileDialog iFileDlg(true);
		if (iFileDlg.DoModal()==IDOK)
		{
			imageFile=iFileDlg.GetPathName();			
		}
	}
	
	Mat img = imread(imageFile, 1);
	_cprintf("load image %s\n", imageFile.c_str());
	//start quad paint
	CQuadPaint aQP;
	aQP.setImage(img);

	if (aQP.DoModal()==IDOK)
	{
		_cprintf("quad paint complete.\n");
	}
}

void CQuadIntrinsicView::OnIntrinsicU()
{
	// TODO: Add your command handler code here
}

void CQuadIntrinsicView::OnInitialUpdate()
{
	CView::OnInitialUpdate();

	// TODO: Add your specialized code here and/or call the base class
//	MoveWindow(0, 0, 400, 40);
}
